﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Manager_Quangcao_Controls_UC_Chitiet : System.Web.UI.UserControl
{
    BUS_Advertise Ad = new BUS_Advertise();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }
    void LoadData()
    {
        var Id = Request.QueryString["Id"];
        var dt = Ad.Advertise_GetByID(Id);
        txtName.Text = dt.Rows[0]["Name"].ToString();
        txtLink.Text = dt.Rows[0]["Link"].ToString();
        Image1.ImageUrl = dt.Rows[0]["Image"].ToString();
        drlTarget.SelectedValue = dt.Rows[0]["Target"].ToString();
        drlPositon.SelectedValue = dt.Rows[0]["Position"].ToString();
        txtOrder.Text = dt.Rows[0]["Order"].ToString();
        txtDateStar.Text = string.Format("{0:MM/dd/yyyy}", DateTime.Parse(dt.Rows[0]["DateStar"].ToString()));
        txtDateEnd.Text = string.Format("{0:MM/dd/yyyy}", DateTime.Parse(dt.Rows[0]["DateEnd"].ToString()));
        bool trangthai = bool.Parse(dt.Rows[0]["Status"].ToString());
        if (trangthai)
        {
            rbMo.Checked = true;
        }
        else
        {
            rbDong.Checked = true;
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        DTO_Advertise obj = new DTO_Advertise();
        var Id = Request.QueryString["Id"];
        obj.Name = txtName.Text;
        obj.Link = txtLink.Text;
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/Upload/Advertise/" + FileUpload1.FileName));
            obj.Images = "~/Upload/Advertise/" + FileUpload1.FileName;
        }
        obj.Target = drlTarget.SelectedValue;
        obj.Position = int.Parse(drlPositon.SelectedValue);
        obj.Order = int.Parse(txtOrder.Text);
        obj.DateStar = txtDateStar.Text;
        obj.DateEnd = txtDateEnd.Text;
        if (rbMo.Checked)
        {
            obj.Status = true;
        }
        else
        {
            obj.Status = false;
        }
        Ad.Advertise_UpdateByAll(Id, obj);
        Response.Redirect(Request.RawUrl);
    }
}